package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

//    @AutoFill(value = OperationType.UPDATE)
//    void updateDish(DishDTO dishDTO);


    @AutoFill(value = OperationType.INSERT)
    void addDishes(Dish dish);

    /**
     * @param name,categoryId,status
     * 菜品分页查询
     * @return
     * */
    //List<DishVO> queryDish(DishPageQueryDTO dishPageQueryDTO);
    List<DishVO> queryDish(String name,Integer categoryId,Integer status);

    /**
     * @param id
     * 批量删除菜品
     * @return
     * */
    void delete(Long id);

    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据id查询菜品
     * @param id
     * @return
     * */
    DishVO selectById(Long id);

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * */
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> selectByCategoryId(Integer categoryId);

    /**
     * 起售或停售
     * */
    @AutoFill(OperationType.UPDATE)
    @Update("update dish set status = #{status} where id=#{id}")
    void changeStatus(Integer status,Long id);

    List<DishVO> list(Dish dish);

    /**
     * 查询菜品价格
     * */
    @Select("select * from dish where id=#{id}")
    Dish selectPrice(Long id);

    /**
     * 根据状态查询菜品数量
     * */
    @Select("select count(id) from dish where status=#{status}")
    Integer getDishesByStatus(Integer status);
}
